import request from '@/utils/request'
// import qs from 'qs'

// 获取绑定策略列表
export function getBindArray (params) {
  var data = fromData(params)
  return request({
    url: '/bind/getBindArray',
    method: 'post',
    data
  })
}

// 增加绑定策略
export function addBind (params) {
  var data = fromData(params)
  return request({
    url: '/bind/addBind',
    method: 'post',
    data
  })
}

// 删除绑定策略
export function delBind (params) {
  var data = fromData(params)
  return request({
    url: '/bind/del_bind',
    method: 'post',
    data
  })
}

// 获取绑定功能状态
export function getBindStatus (params) {
  var data = fromData(params)
  return request({
    url: '/bind/getBindStatus',
    method: 'post',
    data
  })
}

// 修改绑定功能状态
export function changeBindStatus (params) {
  var data = fromData(params)
  return request({
    url: '/bind/changeBindStatus',
    method: 'post',
    data
  })
}

// 自动探测
export function autoDetect (params) {
  var data = fromData(params)
  return request({
    url: '/bind/autoDetect',
    method: 'post',
    data
  })
}

// 自动探测增加绑定策略
export function addBindByAuto (params) {
  var data = fromData(params)
  return request({
    url: '/bind/addBindByAuto',
    method: 'post',
    data
  })
}

// 获取主动防御信息
export function getArpDefenseInfo (params) {
  var data = fromData(params)
  return request({
    url: '/bind/getArpDefenseInfo',
    method: 'post',
    data
  })
}

// 设置主动防御信息
export function setArpDefenseInfo (params) {
  var data = fromData(params)
  return request({
    url: '/bind/setArpDefenseInfo',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
